# !/usr/bin/env python
# -*- coding: utf-8 -*-
# ///////////////////////////////////////////////////////////////
# @File    :   getImageBaseData.py
# @Time    :   2024/08/21 14:39:56
# @Author  :   kai.luo
# @Version :   1.0.0
# @Desc    :   获取医疗图片中头部信息的公共库
# ///////////////////////////////////////////////////////////////

from moudles.Common.common import *
from moudles.ColorDopplerReportForm.commonLibrary.getImageHeaderData import HeaderInfo
import copy
import traceback


class SichuanHeaderInfo(object):
    """
    姓名,性别,年龄
    病历号,科室,标本情况
    联系电话,采样时间,接收时间
    Args:
        object (_type_): _description_
    """

    def __init__(self, **kwarg) -> None:

        # 初始化参数
        self.commonXList = list()
        self.commonPosValue = list()

        # # 初始化公共头部库
        self.comonHeaderInfo = HeaderInfo()

    def getHospitalName(self, data: list):
        hospitalName = self.comonHeaderInfo.getHospitalName(data)

        return hospitalName

    def getHeaderInfo(self, data: list):
        """
        Args:
            data (_type_): _description_
        """
        # print(f'parserHeader---{data}')
        # 先过滤键值对数据
        self.getKeyValue(data)
        # print(f'self.commonPosValue----{self.commonPosValue}')

        # 筛选分离出key和value在一起的情况
        header_key_value_list = self.comonHeaderInfo.checkSplitKeyValue(data)
        self.commonPosValue = self.commonPosValue + header_key_value_list

        # 过滤满足显示要求的的键值对
        header_key_value = self.comonHeaderInfo.filterMatchKeyValue(self.commonPosValue)

        return header_key_value

    def getKeyValue(self, data: list):
        data = [x for x in data if x]
        try:
            header_kv_list = data[0]
            copy_data = copy.deepcopy(data[1:])

            text_m = header_kv_list[1][0]
            x_m, y_m = header_kv_list[0][0]
            for index, item_vale_list in enumerate(copy_data):
                text = item_vale_list[1][0]
                x, y = item_vale_list[0][0]
                if abs(x_m-x) <= 90 and abs(y_m-y) <= 7:
                    self.commonPosValue.append([text_m, text])
                    copy_data.remove(item_vale_list)
                    break

            if len(copy_data) != 0:
                self.getKeyValue(copy_data)
        except:
            print(traceback.print_exc())
